package net.java.mediasystems.database.core.model;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

@Entity
@Table(name ="MEDIA_ITEM_TO_GENRE")
public class MediaItemToGenreAssociation {
	
	@EmbeddedId
	private MediaItemToGenreAssociationId id;
	
	@ManyToOne
	@PrimaryKeyJoinColumn(name ="MEDIA_ITEM_ID", referencedColumnName = "ID")
	private MediaItem mediaItem;
	
	@ManyToOne
	@PrimaryKeyJoinColumn(name ="GENRE_ID", referencedColumnName = "ID")
	private Genre genre;
	
	@Override
	public int hashCode() {
		final int prime = 43;
		int result = 1;
		
		result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
		return result;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		MediaItemToGenreAssociation other = (MediaItemToGenreAssociation) obj;
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		return true;
	}
}
